#include"chen.h"

int 
main(int argc, char **argv )
{
	int listenfd, connfd;
	pid_t childpid;

	time_t ticks;

	char buff[MAXLINE];

	struct sockaddr_in servaddr, cliaddr;
	socklen_t clilen;

	listenfd = Socket( AF_INET, SOCK_STREAM, 0 );

	bzero( &servaddr, sizeof( servaddr ) );

	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.s_addr = htonl( INADDR_ANY );
	servaddr.sin_port = htons( 13 );

	Bind( listenfd, ( struct sockaddr * ) &servaddr, sizeof( servaddr ) );

	Listen( listenfd, 10 );

	for ( ; ; ) {
		clilen = sizeof( cliaddr );
		
		connfd = Accept( listenfd, ( struct sockaddr * ) &cliaddr, &clilen );
		ticks = time( NULL );

		snprintf( buff, sizeof( buff ), "%.24s\r\n", ctime( &ticks ) );
		write( connfd, buff, strlen( buff ) );
		close( connfd );
	}
}

